//
//  WFSecondChannelViewController.m
//  FAKER
//
//  Created by Jianwei on 15/11/5.
//  Copyright © 2015年 YHLai. All rights reserved.
//

#import "WFSecondChannelViewController.h"
#import "AllHeader.h"
#import "FitHeader.h"
#import "WFChannelListTableViewCell.h"
#import "WFChannelDetailViewController.h"
@interface WFSecondChannelViewController ()<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, strong)BaseClassTableViewCell *listTableViewCell;
@property(nonatomic, strong)NSMutableArray *dataSourceArray;
@property(nonatomic, strong)BaseClassTableView *channelListTableView;
@end

@implementation WFSecondChannelViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor redColor];
//    self.title = _model.title;
    
}
- (void)getData
{
    NSArray *array = _model.sons;
    for (NSDictionary *dic in array) {
        WFSecondChannelListModel *model = [[WFSecondChannelListModel alloc]init];
        [model setValuesForKeysWithDictionary:dic];
        [_dataSourceArray addObject:model];
    }
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = 0;
}
- (void)loadView
{
    [super loadView];
    _dataSourceArray = [NSMutableArray array];
    [self getData];
    _channelListTableView = [[BaseClassTableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:UITableViewStylePlain];
    _channelListTableView.delegate = self;
    _channelListTableView.dataSource = self;
    _channelListTableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    [self.view addSubview:_channelListTableView];
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"channelList";
    WFChannelListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[WFChannelListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.model = _dataSourceArray[indexPath.row];
    cell.selectionStyle = 0;
//    cell.layer.transform = CATransform3DMakeScale(0.3, 0.3, 0.1);
//    [UIView animateWithDuration:0.5 animations:^{
//        cell.layer.transform = CATransform3DMakeScale(1, 1, 0.1);
//    }];
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSourceArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WFChannelDetailViewController *wc = [[WFChannelDetailViewController alloc]init];
    wc.api_url = [_dataSourceArray[indexPath.row] api_url];
    [self.navigationController pushViewController:wc animated:1];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
